package com.net.oil.main.adapter;
/*
 * Created by lch on 2018/2/27 0027.
 */

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.net.oil.main.bean.NewsTypeBean;
import com.net.oil.news.NewsListFragment;

import java.util.ArrayList;
import java.util.List;

public class NewsViewPagerAdapter extends FragmentStatePagerAdapter {

    private List<NewsTypeBean> newsTypeBeenList;

    public NewsViewPagerAdapter(FragmentManager fm) {
        super(fm);
        newsTypeBeenList = new ArrayList<>();
    }

    public void updateDate(List<NewsTypeBean> newsTypeBeenList){
        this.newsTypeBeenList.addAll(newsTypeBeenList);
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        return NewsListFragment.newInstance(newsTypeBeenList.get(position).getCatId());
    }

    @Override
    public int getCount() {
        return newsTypeBeenList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return newsTypeBeenList.get(position).getCatName();
    }
}
